<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>canvas渐变</title>
	</head>
	<body>
		<canvas id="myCanvas" width="300" height="100" style="border:1px solid #c3c3c3;">
			
		</canvas>
		<script>
			var c = document.getElementById("myCanvas");
			var ctx = c.getContext("2d"); //获取该canvas的2D绘图环境对象
			//线性渐变
			// var grd = ctx.createLinearGradient(0, 0, 200, 0);
			// grd.addColorStop(0, "red");
			// grd.addColorStop(1, "white");
			// ctx.fillStyle = grd;
			// ctx.fillRect(10, 10, 150, 80);
			//圆形渐变
			var grd = ctx.createRadialGradient(75, 50, 5, 90, 60, 100);
			grd.addColorStop(0, "red");
			grd.addColorStop(1, "white");
			ctx.fillStyle = grd;
			ctx.fillRect(10, 10, 150, 80);
		</script>
	</body>
</html>